<?php
header("Content-type: text/html; charset=utf-8");
include 'mysql.php';
if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
{
    $param = $_POST['Form'];
    $password = $param['password'];
    $name = $param['name'];
    $result = $mysqli->query("select * from user where `name`='".$name."' and `password`='".$password."' ");
    $row =$result->fetch_assoc();
    if($row['id'])
    {
         setcookie("name",$name,time()+36000);
         setcookie("id",$row['id'],time()+36000);
         header("Location:/");
    }
    else
    {
        $query = "INSERT INTO  `user` (`id`,`name`,`password`) VALUES (NULL, '".$name."','".$password."')";
        $result=$mysqli->query($query);
        if($result)
        {
            setcookie("name",$name,time()+36000);
            setcookie("id",$result,time()+36000);
            header("Location:/");
        }
        else
        {
            echo  "<script>alert('注册失败');window.location.href='/'</script>";
        }
    }

}
